#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/10/31 20:25
# @Author  : summer
# @Email   : 610658552@qq.com
# @File    : sms_send_log.py
# @Software: PyCharm
# @Desc    :

from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters
from rest_framework.generics import GenericAPIView

from common.utils.pagination import EnhancedPageNumberPagination
from common.utils.rsp import success_response
from ssms.filters.filter_sms_log import SMSLogFilter
from ssms.models import SMSLog
from ssms.sers.ser_sms_log import SMSLogSerializer


class SMSLogListView(GenericAPIView):
    """
    SMSTemplate列表查询 + 新增接口
    - GET: 分页查询短信模板列表
    - POST: 新增短信模板
    """
    queryset = SMSLog.objects.filter(is_delete=0, pt_flag=0)
    serializer_class = SMSLogSerializer
    pagination_class = EnhancedPageNumberPagination
    filter_backends = [DjangoFilterBackend, filters.OrderingFilter]
    filterset_class = SMSLogFilter
    ordering_fields = ["create_time", "sort_num", "name", "content"]

    # ordering = ["-sort_num", "-create_time"]

    def get(self, request):
        """查询短信模板列表"""
        filtered_qs = self.filter_queryset(self.get_queryset())
        page_qs = self.paginate_queryset(filtered_qs)
        serializer = self.get_serializer(page_qs, many=True)
        paginated_data = self.paginator.get_paginated_response(serializer.data).data
        return success_response(data=paginated_data, message="短信模板列表查询成功")


